import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// todo：底部菜单
bottomNavWidget({
  required int currentIndex,
  required Function(int) onTap,
  required List<BottomNavModel> menuData,
  int? count,
  Color? bgColor,
}){
  return Container(
    width: Get.width,
    // 判断部分手机 底部存在虚拟按键或者小黑条
    height: Get.bottomBarHeight > 0.0 ? Get.bottomBarHeight+1 : 65,
    color: bgColor,
    decoration: BoxDecoration(
      border: Border(top: BorderSide(color: Color(0xE0E0E0FF),width: 0.5))
    ),
    child: SafeArea(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: List.generate(menuData.length, (index){
          // Material->Ink 设置点击水波纹
          return Material(
            color: Colors.transparent,
            child: Ink(
              child: InkWell(
                onTap: (){
                  onTap(index);
                },
                child: Container(
                  width: Get.width / menuData.length,
                  padding: EdgeInsets.all(8),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Image.asset("${index != currentIndex ? menuData[index].unImg : menuData[index].img}",width: 28,height: 28,),
                      Expanded(child: Text("${menuData[index].label ?? ''}",maxLines: 1,overflow: TextOverflow.ellipsis,style: TextStyle(fontSize: 14,color: index != currentIndex ? menuData[index].unColor : menuData[index].color),),)
                    ],
                  ),
                ),
              ),
            ),
          );
        }),
      ),
    ),
  );
}

/// 菜单模型
class BottomNavModel{
  String? label;
  String? img;// 选中
  String? unImg; // 未选中
  Color? color;// 选中
  Color? unColor;// 未选中
  bool? showMsg;// 是否显示小红点
  int? count;// 小红点计数

  BottomNavModel({this.label, this.img, this.unImg, this.color, this.unColor, this.count:0 , this.showMsg:false});
}